package com.grass.p019lv.activity;

import android.view.View;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.event.AttentionPhoenixEvent;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.base.view.StatusControlLayout;
import com.grass.appointment.model.UserPhoenixModel;
import com.grass.p019lv.R;
import com.grass.p019lv.adapter.FansMessageAdapter;
import com.grass.p019lv.bean.FansBean;
import com.grass.p019lv.bean.FansOrFollowBean;
import com.grass.p019lv.databinding.ActivityFansMessageLayoutBinding;
import com.grass.p019lv.viewmodel.MessageModel;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import java.util.List;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/* renamed from: com.grass.lv.activity.FansMessageActivity */
public class FansMessageActivity extends BaseActivity<ActivityFansMessageLayoutBinding>
        implements OnRefreshLoadMoreListener, ItemClickListener {
    private FansMessageAdapter adapter;
    private MessageModel model;
    private int page = 1;
    public int userId;
    private UserPhoenixModel userModel;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return R.layout.activity_fans_message_layout;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(this.binding.toolBar).init();
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        EventBus.getDefault().register(this);
        ((ActivityFansMessageLayoutBinding) this.binding).setClick(new OnClick());
        this.model = (MessageModel) new ViewModelProvider(this).get(MessageModel.class);
        this.userModel = (UserPhoenixModel) new ViewModelProvider(this).get(UserPhoenixModel.class);
        FansMessageAdapter fansMessageAdapter = new FansMessageAdapter();
        this.adapter = fansMessageAdapter;
        fansMessageAdapter.setItemListener(this);
        ((ActivityFansMessageLayoutBinding) this.binding).include.recycler.setPadding(0, UiUtils.dp2px(15), 0, UiUtils.dp2px(15));
        ((ActivityFansMessageLayoutBinding) this.binding).include.recycler.setLayoutManager(new LinearLayoutManager(this));
        ((ActivityFansMessageLayoutBinding) this.binding).include.recycler.setAdapter(this.adapter);
        ((ActivityFansMessageLayoutBinding) this.binding).include.refresh.setOnRefreshListener(this);
        ((ActivityFansMessageLayoutBinding) this.binding).include.refresh.setOnLoadMoreListener(this);
        ((ActivityFansMessageLayoutBinding) this.binding).include.statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.activity.FansMessageActivity.View$OnClickListenerC28701 */

            public void onClick(View view) {
                FansMessageActivity.this.page = 1;
                ((ActivityFansMessageLayoutBinding) FansMessageActivity.this.binding).setStatus(2);
                FansMessageActivity.this.model.userFansList(FansMessageActivity.this.userId, FansMessageActivity.this.page);
            }
        });
        this.model.getFansLive().observe(this, new Observer<BaseRes<FansOrFollowBean>>() {
            /* class com.grass.p019lv.activity.FansMessageActivity.C28712 */

            public void onChanged(BaseRes<FansOrFollowBean> baseRes) {
                FansMessageActivity.this.hideLoading();
                if (baseRes.getCode() == 200) {
                    FansOrFollowBean data = baseRes.getData();
                    if (FansMessageActivity.this.page == 1) {
                        if (data == null || data.getList() == null || data.getList().size() == 0) {
                            ((ActivityFansMessageLayoutBinding) FansMessageActivity.this.binding).setStatus(4);
                            return;
                        }
                        FansMessageActivity.this.adapter.setDomain(data.getDomain());
                        List<FansBean> list = data.getList();
                        FansMessageActivity.this.adapter.setData(list);
                        if (list.size() < 30) {
                            ((ActivityFansMessageLayoutBinding) FansMessageActivity.this.binding).setStatusRefresh(2);
                        }
                    } else if (data == null || data.getList() == null || data.getList().size() == 0) {
                        ((ActivityFansMessageLayoutBinding) FansMessageActivity.this.binding).setStatusRefresh(2);
                    } else {
                        List<FansBean> list2 = data.getList();
                        FansMessageActivity.this.adapter.setDatasInEnd(list2);
                        if (list2.size() < 30) {
                            ((ActivityFansMessageLayoutBinding) FansMessageActivity.this.binding).setStatusRefresh(2);
                        }
                    }
                } else if (FansMessageActivity.this.page == 1) {
                    ((ActivityFansMessageLayoutBinding) FansMessageActivity.this.binding).setStatus(1);
                } else {
                    ToastUtils.getInstance().showWrong(baseRes.getMsg());
                }
            }
        });
        ((ActivityFansMessageLayoutBinding) this.binding).setStatus(2);
        this.model.userFansList(this.userId, this.page);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        int i = this.page + 1;
        this.page = i;
        this.model.userFansList(this.userId, i);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        this.model.userFansList(this.userId, 1);
    }

    public void hideLoading() {
        ((ActivityFansMessageLayoutBinding) this.binding).setStatus(0);
        ((ActivityFansMessageLayoutBinding) this.binding).setStatusRefresh(1);
    }

    public static void showStatusView(StatusControlLayout statusControlLayout, int i) {
        statusControlLayout.showStatusView(i);
    }

    public static void refreshStatus(SmartRefreshLayout smartRefreshLayout, int i) {
        if (i == 1) {
            smartRefreshLayout.finishLoadMore();
            smartRefreshLayout.finishRefresh();
        }
        if (i == 2) {
            smartRefreshLayout.finishLoadMoreWithNoMoreData();
        }
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (view.getId() == R.id.btn_follow) {
            if (!isOnClick()) {
                FansBean fansBean = (FansBean) this.adapter.getDataInPosition(i);
                boolean z = !fansBean.isIsAttention();
                fansBean.setIsAttention(z);
                this.adapter.notifyItemChanged(i, Integer.valueOf((int) R.id.btn_follow));
                this.userModel.isFollowUser(fansBean.getUserId(), z);
                EventBus.getDefault().post(new AttentionPhoenixEvent(fansBean.getUserId(), z));
            }
        } else if (!isOnClick()) {
            ARouter.getInstance().build(Constance.USER_INFO_ACTIVITY).withInt(Key.USER_ID, ((FansBean) this.adapter.getDataInPosition(i)).getUserId()).navigation();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onFansOrFollowEvent(AttentionPhoenixEvent attentionPhoenixEvent) {
        if (attentionPhoenixEvent != null) {
            for (FansBean fansBean : this.adapter.getData()) {
                if (attentionPhoenixEvent.getUserId() == fansBean.getUserId()) {
                    fansBean.setIsAttention(attentionPhoenixEvent.isAttention());
                }
            }
            this.adapter.notifyDataSetChanged();
        }
    }

    /* renamed from: com.grass.lv.activity.FansMessageActivity$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void btnBack() {
            FansMessageActivity.this.finish();
        }
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        MessageModel messageModel = this.model;
        if (messageModel != null) {
            messageModel.cancelHttp();
        }
        super.onDestroy();
    }
}
